/*
 * Copyright © 2019-2020  Whale Cloud, Inc. All Rights Reserved.
 *
 * Notice: Whale Cloud Inc copyrights this specification.
 * No part of this specification may be reproduced in any form or means,
 * without the prior written consent of Whale Cloud Inc.
 *
 */
package com.wteam.modules.system.web;

import com.wteam.annotation.permission.PermissionGroup;
import com.wteam.domain.vo.R;
import com.wteam.modules.system.domain.DevelopPlanCreditTypeMap;
import com.wteam.modules.system.service.DevelopPlanCreditTypeMapService;
import com.wteam.modules.system.domain.criteria.DevelopPlanCreditTypeMapQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
 * 培养计划学分类型映射 控制层.
 *
 * @author herry_wong
 * @since 2020-12-29
 */
@SuppressWarnings({"rawtypes"})
@Api(value = "培养计划学分类型映射Controller", tags = {"新增：培养计划学分类型映射操作"})
@RestController
@RequiredArgsConstructor
@RequestMapping("api/developPlanCreditTypeMap")
@PermissionGroup(value = "DEVELOPPLANCREDITTYPEMAP", aliasPrefix = "培养计划学分类型映射")
public class DevelopPlanCreditTypeMapController {

    private final DevelopPlanCreditTypeMapService developPlanCreditTypeMapService;

    //@Log("查询培养计划学分类型映射分页")
    @ApiOperation(value = "查询培养计划学分类型映射分页")
    @GetMapping(value = "/page")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:list')")
    public R getDevelopPlanCreditTypeMaps(DevelopPlanCreditTypeMapQueryCriteria criteria, Pageable pageable){
        return R.ok(developPlanCreditTypeMapService.queryAll(criteria, pageable));
    }

    //@Log("查询培养计划学分类型映射详情")
    @ApiOperation(value = "查询培养计划学分类型映射详情")
    @GetMapping(value = "/get/{id}")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:list')")
    public R get(@PathVariable Long id){
        return R.ok(developPlanCreditTypeMapService.findDTOById(id));
    }

    //@Log("新增培养计划学分类型映射")
    @ApiOperation(value = "新增培养计划学分类型映射")
    @PostMapping(value = "/add")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:add')")
    public R create(@Validated @RequestBody DevelopPlanCreditTypeMap resources){
        return R.ok(developPlanCreditTypeMapService.create(resources));
    }

    //@Log("修改培养计划学分类型映射")
    @ApiOperation(value = "修改培养计划学分类型映射")
    @PostMapping(value = "/edit")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:edit')")
    public R update(@Validated(DevelopPlanCreditTypeMap.Update.class) @RequestBody DevelopPlanCreditTypeMap resources){
        developPlanCreditTypeMapService.update(resources);
        return R.ok();
    }

    //@Log("删除培养计划学分类型映射")
    @ApiOperation(value = "删除培养计划学分类型映射")
    @PostMapping(value = "/del")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:del')")
    public R delete(@RequestBody Set<Long> ids){
        developPlanCreditTypeMapService.deleteAll(ids);
        return R.ok();
    }

    //@Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@R.check('DEVELOPPLANCREDITTYPEMAP:all', 'DEVELOPPLANCREDITTYPEMAP:list')")
    public void download(HttpServletResponse response, DevelopPlanCreditTypeMapQueryCriteria criteria) throws IOException {
        developPlanCreditTypeMapService.download(developPlanCreditTypeMapService.queryAll(criteria), response);
    }

}